package com.cqust.controller;

import com.cqust.pojo.Attendance;
import com.cqust.service.AttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class AttendanceController {

    @Autowired
    private AttendanceService attendanceService;
    // 员工出勤信息
    @RequestMapping("/attendance")
    public String Attendance(Model model){
        model.addAttribute("attendances",attendanceService.getAttendances());
        return "attendance";
    }
    // 员工在个人信息板块完成上班打卡上传
    @PostMapping("/addAttendance")
    public String addAttendance(Attendance attendance){
        attendanceService.addAttendance(attendance);
        return "myInfo";
    }
    //下班打卡
    @PostMapping("/updateAttendance")
    public String updateAttendance(String eid,String offDate){
        attendanceService.updateAttendance(eid,offDate);
        return "myInfo";
    }
    //判断该员工是否完成打卡
    @ResponseBody
    @PostMapping("/IsAttendance")
    public Attendance IsAttendance(String eid){
        return attendanceService.getAttendance(eid);
    }
    //删除出勤记录
    @RequestMapping("/deleteAttendance/{eid}")
    public String deleteAttendance(@PathVariable("eid") String eid){
        attendanceService.deleteAttendance(eid);
        return "redirect:/attendance";
    }
}
